﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
using Kokomo.PeInspector.Reflection.Disassembly;

namespace Kokomo.PeInspector.Reflection
{
	/// <summary>
	/// Represents an <see cref="AssemblyResource"/> within the UI.
	/// </summary>
	public class AssemblyResourceItem
	{
		/// <summary>
		/// Gets the name of the resource.
		/// </summary>
		public string Name { get; private set; }
		/// <summary>
		/// Gets the <see cref="AssemblyResource"/>.
		/// </summary>
		public AssemblyResource Resource { get; private set; }

		/// <summary>
		/// Initializes a new instance of <see cref="AssemblyResourceItem"/>.
		/// </summary>
		/// <param name="resource">The resource to display.</param>
		/// <exception cref="ArgumentNullException"><paramref name="resource"/> is <c>null</c>.</exception>
		public AssemblyResourceItem(
			AssemblyResource resource
			)
		{
			if (resource == null) throw new ArgumentNullException("resource");

			this.Name = resource.Name;
			this.Resource = resource;
			this._size = new Lazy<int>(this.Resource.DetermineSize);
		}

		private Lazy<int> _size;
		/// <summary>
		/// Gets the size of the resource, in bytes.
		/// </summary>
		/// <remarks>
		/// This property invokes <see cref="AssemblyResource.DetermineSize"/>
		/// the first time it is invoked.
		/// </remarks>
		public int Size { get { return this._size.Value; } }
	}
}
